package com.springapp.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.springapp.model.Cathegory;
import com.springapp.repository.CathegoryRepository;
import com.springapp.service.CathegoryService;

/*
 * 
 * @uthor Sim4ik
 * 
 */

@Service
public class CathegoryServiceImpl implements CathegoryService {

    @Autowired
    CathegoryRepository cathegoryRepository;

    public Cathegory getById(Integer id) {
        return cathegoryRepository.findOne(id);
    }

    public List<Cathegory> getAll() {
        return (ArrayList<Cathegory>) cathegoryRepository.findAll();
    }

    public void create(Cathegory cathegory) {
        cathegoryRepository.save(cathegory);
    }

    public Cathegory update(Cathegory cathegory){
        return cathegoryRepository.save(cathegory);
    }

    public void delete(Integer id) {
        cathegoryRepository.delete(id);
    }
}